<?php
namespace app\mobile\model;

use think\Model;

class BaseModel extends Model
{
    public static function _initialize()
    {
        $field = self::getTableInfo('','fields');
        $flip_field = array_flip($field);
        foreach ($flip_field as &$v){
            $v = '';
        }
        return $flip_field;
    }

    public static function init()
    {
        self::event('before_insert',function ($e){
            !key_exists('create_time',self::_initialize())?:$e->create_time = time();
        });
        self::event('before_update',function ($e){
            !key_exists('update_time',self::_initialize())?:$e->update_time = time();
        });
    }
    public function getThumbImgAttr($value){
        return $value?$value:'static/mobile/img/empty_img.png';
    }
}